<template>
  <view
    class="content ba_img"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eeeeee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">星河</view>
    </view>
    <view class="box1">
      <view class="inp">
        <u--input
          placeholder="搜索感兴趣的问题"
          border="none"
          placeholderStyle="font-size:30rpx;color:#ADADAD;"
          prefixIcon="search"
          prefixIconStyle="font-size: 42rpx;color: #ADADAD"
          color="#ADADAD"
          v-model="value"
          @change="change"
          inputAlign="left"
          @confirm="confirm"
        ></u--input>
      </view>
      <view class="tabs">
        <view :class="current == 0 ? 'active' : ''" @click="handTab(0)">
          按主题
        </view>
        <view :class="current == 1 ? 'active' : ''" @click="handTab(1)">
          按上架时间
        </view>
        <view :class="current == 2 ? 'active' : ''" @click="handTab(2)">
          按热度
        </view>
      </view>

      <view class="find">
        <view class="find_left"> 发现星球 </view>
        <view class="find_right" @click="toDetail">
          更多<u-icon name="arrow-right" size="16" color="#ADADAD"></u-icon>
        </view>
      </view>
      <scroll-view
        :style="{
          height: scrollHeihgt + 'px',
        }"
        :scroll-y="true"
        @scroll="scroll"
      >
        <starList :isWhite="true" :list="{ data: list }"></starList>
        
      </scroll-view>
      
    </view>
	<floatingBall></floatingBall>
  </view>
</template>

<script>
// import starList from './components/starList.vue'
import starList from "@/components/starList.vue"; //星河
import { xingheList } from "@/common/api/start.js";
export default {
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      windowHeihgt: 0,
      value: "",
      list: [],
      scrollHeihgt: 0,
      current: -1,
      type: "",
      typeList: ["type", "status_time", "people_total"],
      search: "",
    };
  },
  components: {
    starList,
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    const windowHeihgt = statusBarHeight.windowHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs").fields({
        size: true,
      });
      query.select(".inp").fields({
        size: true,
      });
      query.exec((data) => {
        console.log("data", data);
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - 120;
      });
    });
  },
  onLoad() {
    this.getList();
  },
  methods: {
    handTab(i) {
      if (this.current == i) {
        this.current = -1;
        this.type = "";
        return;
        this.getList();
      }
      this.type = this.typeList[i];
      this.current = i;
      this.getList();
    },
    getList() {
      xingheList({
        order: this.type,
        search: this.value,
      }).then((res) => {
        console.log("resssss", res);
        this.list = res.data.list.data;
      });
    },
    confirm(e) {
      this.getList();
    },
    change(e) {
		this.getList();
	},
    toDetail() {
      uni.navigateTo({
        url: "/pages/distinguish/findStart",
      });
    },
    scroll(e) {},
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ba_img {
  position: fixed;
  margin: 0;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  box-sizing: border-box;
}

.head {
  width: 100%;
  padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}

.box1 {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
}

.box1 {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;

  .inp {
    width: 100%;
    height: 80rpx;
    background: rgba(39, 44, 41, 0.5);
    border-radius: 40rpx;
    display: flex;
    align-items: center;
    margin-top: 32rpx;
  }

  .tabs {
    width: 100%;
    display: flex;
    margin-top: 32rpx;
    .active {
      color: #eeeeee;
    }
    view {
      font-size: 28rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #adadad;
      padding: 7rpx 30rpx;
      border-radius: 32rpx;
      margin-right: 16rpx;
      background: rgba(39, 39, 39, 0.5);
    }
  }

  .find {
    width: 100%;
    height: 106rpx;
    background: rgba(39, 39, 39, 0.5);
    border-radius: 16rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32rpx;
    box-sizing: border-box;
    margin-top: 40rpx;

    .find_left {
      font-size: 28rpx;
      font-family: PingFang SC-Bold, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
    }

    .find_right {
      display: flex;
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #adadad;
    }
  }
}
</style>